<?php

require('../phpMQTT.php');

$server = 'localhost';     // change if necessary
$port = 1883;                     // change if necessary
$username = '';                   // set your username
$password = '';                   // set your password
$client_id = 'phpMQTT-publisher'; // make sure this is unique for connecting to sever - you could use uniqid()

$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id);

if ($mqtt->connect(true, NULL, $username, $password)) {
    // qos ＝ 0：仅发一次，不管是否能收到
    // qos ＝ 1：没返回一直发，可能有重复接收
    // qos ＝ 2：保证必须收到，并且不重复
	$mqtt->publish('bluerhinos/phpMQTT/examples/publishtest1', 'Hello World! at ' . date('Y-m-d H:i:s'), 0, false);
	$mqtt->close();
} else {
    echo "Time out!\n";
}
